import { defineStore } from 'pinia';
import { messageFn } from '../../utils';
import { getReceived, getPrronventory, PostReplen } from '/@/api/comprehensive/reconciliation';

interface ReceivedType {
  reconList: any[];
  rinvenList: any[];
}

export const ReconciliationStore = defineStore('Reconciliation_store', {
  state: (): ReceivedType => {
    return {
      reconList: [],
      rinvenList: [],
    };
  },
  actions: {
    async setReceivedList(obj: object) {
      const { code, data, msg, total } = await getReceived(obj);
      if (code === 0) {
        this.reconList = data;
        return total;
      } else {
        messageFn('error', msg);
      }
    },
    async setrrinvenList(obj: object) {
      const { code, data, msg, total } = await getPrronventory(obj);
      if (code === 0) {
        this.rinvenList = data;
        console.log(data, '对账明细');

        return total;
      } else {
        messageFn('error', msg);
      }
    },

    async Postreple(obj: object) {
      const { code, data, msg, total } = await PostReplen(obj);
      if (code === 0) {
        messageFn('successs', msg);
        return true;
      } else {
        messageFn('error', msg);
      }
    },
  },
});
